package com.example.common;

import java.util.Arrays;

public class MyUtils {
    public static char[][] copyOf(char[][] arr1) {
        int n = arr1.length;
        char[][] res = new char[n][];
        for (int i = 0; i < n; i++) {
            res[i] = Arrays.copyOf(arr1[i], arr1[i].length);
        }
        return res;
    }

    public static char[][] toCharArray(String[] problem) {
        char[][] chars = new char[9][];
        for (int i = 0; i < 9; i++) {
            chars[i] = problem[i].toCharArray();
        }
        return chars;
    }

    public static char[][] toCharArray(String s1) {
        String[] split = split(s1);
        return toCharArray(split);
    }

    public static String printString(char[][] chars) {
        StringBuilder sb = new StringBuilder();
        sb.append("\n");
        for (int i = 0; i < chars.length; i++) {
            sb.append(chars[i]).append("\n");
        }
        return sb.toString();
    }

    public static String toString(char[][] chars) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < chars.length; i++) {
            sb.append(chars[i]);
        }
        return sb.toString();
    }

    public static String[] split(String s1) {
        String[] strs = new String[9];
        for (int i = 0; i < 9; i++) {
            strs[i] = s1.substring(9 * i, 9 * i + 9);
        }
        return strs;
    }

    public static boolean isEmpty(char[][] board) {
        return board == null || board.length == 0;
    }
}
